home *** CD-ROM | disk | FTP | other *** search
/ Trading on the Edge / Trading On The Edge - CD-ROM Toolkit (Wayzata Technology)(2031)(1994).bin / pc / mac_file / vendor_d / neuralwa / nw2v50 / usermath.h < prev    next >
Text File  |  1993-08-23  |  60KB  |  1,199 lines

  1. /* $Id$ */
  2. /* $Log$ */
  3. /* 1-18-91 (usermath.h)   Header for User-Defined Neuro-Dynamics */
  4.  
  5. /************************************************************************
  6.  * Copyright(C) 1987-1992 NeuralWare Inc                                *
  7.  * Penn Center West, IV-227, Pittsburgh, PA 15276                       *
  8.  * Telephone: (412) 787-8222    FAX: (412) 787-8220                     *
  9.  *                                                                      *
  10.  * All rights reserved.  No part of this program may be reproduced,     *
  11.  * stored in a retrieval system, or transmitted, in any form or by any  *
  12.  * means, electronic, mechanical, photocopying, recording or otherwise  *
  13.  * without the prior written permission of the copyright owner,         *
  14.  * NeuralWare, Inc.                                                     *
  15.  *                                                                      *
  16.  *                          PROPRIETARY NOTICE                          *
  17.  *                                                                      *
  18.  * This document is the property of NeuralWare, Inc. and contains       *
  19.  * trade-secrets and other proprietary information.  The information    *
  20.  * herein is reserved as proprietary to NeuralWare, and is not to be    *
  21.  * published, reproduced, copied, disclosed, used, or reverse           *
  22.  * engineered without the express written consent of a duly authorized  *
  23.  * representative of NeuralWare.                                        *
  24.  ************************************************************************
  25.  */
  26.  
  27. /************************************************************************/
  28. /*                                                                      */
  29. /*  This header file has already been compiled into the                 */
  30. /*  NeuralWorks Object Library.  It should not be modified              */
  31. /*  in any way                                                          */
  32. /*                                                                      */
  33. /************************************************************************/
  34.  
  35. #ifndef _USERMATH_
  36. #define _USERMATH_
  37.  
  38. #include "host.h"
  39.  
  40. #ifdef PUBLIC_FIELDS
  41. #define SHIELD(a) a
  42. #else
  43. #define SHIELD(a) a
  44. #endif
  45.  
  46. /* problem - TRANS, TRANS_PHYS are defined in n2host.h */
  47.  
  48. #ifdef TRANS
  49. #define TRANS_STRUCT  1 /* use Transputer variants on structures */
  50. #endif
  51. #ifdef TRANS_PHYS
  52. #define TRANS_STRUCT  1 /* use Transputer variants on structures */
  53. #endif
  54.  
  55. /************************************************************************/
  56. /*                                                                      */
  57. /*  Ascii File I/O                                                      */
  58. /*                                                                      */
  59. /************************************************************************/
  60.  
  61. /* 32 bit IEEE floating point Not-A-Number definition. Note that an actual
  62.    NAN must also have a non-trivial significand; i.e. at least one of the
  63.    trailing zeroes in NAN_MASK must be non-zero.  Note: NDPC compiler
  64.    must have bit 22 set for a quiet (non-signalling) NAN  */
  65.  
  66. /*
  67.  * VAX works under later IEEE conventions -- the same constants apply.
  68.  * also, byte reversal swaps/maps (hex) ints and floats identically, so:
  69.  */
  70.  
  71. #if 0 && (defined(VAXULT) || defined(VMS))
  72. #define NAN_MASK  0x00007f80
  73. #define NAN_VALUE (NAN_MASK|0x00014000)
  74. #else
  75. #define NAN_MASK  0x7f800000
  76. #define NAN_VALUE (NAN_MASK|0x00400001)
  77. #endif
  78. #define ULREP(x)  (*((UL *)&(x)))
  79. #define ISNAN(x)  ((ULREP(x)&NAN_MASK)==NAN_MASK)
  80.  
  81. /* ALL the following characters are field separators. Anything with an
  82.    ASCII code less than WHITESPACE is a field separator.  A field is
  83.    defined as a contiguous set of non-separators delimited by separators.
  84.    A record is terminated by a NEWLINE followed by a non-continuation
  85.    character */
  86.  
  87. #define WHITESPACE           ((NINT)' ')
  88. #define COMMA                ((NINT)',')
  89. #define CONTINUATION         ((NINT)'&')
  90. #define COMMENT              ((NINT)'!')
  91.  
  92. /* Number of I/O files allowed open: */
  93. #define NUM_IO_FILES      3
  94. #define   IOFX_LRN        0  /* Learn file index */
  95. #define   IOFX_RCL        1  /* Recall/Test file index */
  96. #define   IOFX_AUX        2  /* Auxiliary file index */
  97.  
  98. /* Number of access schemes for each file: */
  99. #define NUM_ACC_SCHMS     2
  100.  
  101. GLOBALREF NINT  InitRec[NUM_IO_FILES];
  102.  
  103. /************************************************************************/
  104. /*                                                                      */
  105. /*  Type Definitions                                                    */
  106. /*                                                                      */
  107. /************************************************************************/
  108.  
  109. /* use NW std random number generator */
  110. #include "n2rand.h"
  111. IMPORT VOID set_rand ARGLIST((long));
  112. IMPORT SL   nrand();                    /* "long" random number generator */
  113.  
  114. #define A(x,y)    ((x)&(y))             /* "And" of two items */
  115. typedef TEXT  Str16[16];
  116.  
  117.  
  118. #ifndef DP_RUN
  119.  
  120. /* display_msg( ) routine can be used to write ascii strings
  121.    to the NeuralWorks message area; use in conjunction with
  122.    sprintf( ) to display numeric values.  msg_gets() prompts for
  123.    a string to be typed in the message area; if a value of 1 is
  124.    passed to msg_gets(), it returns immediately after a single
  125.    character is typed */
  126.  
  127. VOID   display_msg ARGLIST((XB * ));    /* write a message to message window */
  128. XB    *msg_gets ARGLIST((NINT));        /* get a string from message window */
  129.  
  130.  
  131. #endif /* #ifndef DP_RUN */
  132.  
  133. /************************************************************************/
  134. /*                                                                      */
  135. /*  User Structure Definitions - these definitions                      */
  136. /*  mirror the internal NeuralWorks structure definitions except        */
  137. /*  that many of the fields remain private.  Attempt to access          */
  138. /*  these private fields will have an undetermined effect               */
  139. /*                                                                      */
  140. /************************************************************************/
  141.  
  142. /************************************************************************/
  143. /*                                                                      */
  144. /*  Learning and Recall Schedules                                       */
  145. /*                                                                      */
  146. /************************************************************************/
  147.  
  148. #define SC_NCOLS       5   /* # of columns in a schedule */
  149. #define SC_COEFS       10   /* # sched coefficients */
  150. #define SC_TEXT        14  /* Maximum text length */
  151.  
  152. /* The following structure refers to a single column of a learning
  153.    and recall schedule.  Strangeness is due to compatibilty issues.
  154. */
  155.  
  156. typedef struct {         /* User version of LR Schedule column */
  157.    SL     rstep;
  158.    /* Recall coefficients (SC_COEFS in all)*/
  159. #define SC_RCOEFS(cp) ((SREAL *) &((cp)->rtemp))
  160.    SREAL  rtemp;                    /* recall temperature */
  161.    SREAL  fire;                     /* firing rate */
  162.    SREAL  iclamp;                   /* input clamp */
  163.    SREAL  modf;                     /* mod factor */
  164.    SREAL  gain;                     /* gain */
  165.    SREAL  rcoef[SC_COEFS-5];        /* remaining Coefs */
  166.  
  167.    SL     lcount;
  168.    /* Learn coefficients (SC_COEFS in all)*/
  169. #define SC_LCOEFS(cp) ((SREAL *)&((cp)->ltemp))
  170.    SREAL  ltemp;                    /* learn temperature */
  171.    SREAL  lcoef1;                   /* learning coefficient 1 */
  172.    SREAL  lcoef2;                   /* learning coefficient 2 */
  173.    SREAL  lcoef3;                   /* learning coefficient 3 */
  174.    SREAL  lcoef[SC_COEFS-4];        /* remaining Coefs */
  175. } USR_SC_COL;
  176.  
  177. /* The following structure refers to a complete learning and recall
  178.    schedule.  When an internal (non-user) neuro-dynamics routine is
  179.    called the learn and recall counters are compared to "lcount" and
  180.    "rstep" to see which columns of the schedule should be used. The
  181.    indices of these columns are stored in the layer fields "l_col_x"
  182.    and "r_col_x"; pointers to the actual columns are stored in "l_col_p"
  183.    and "r_col_p".  These column indices and pointers are also calculated
  184.    for user defined neuro-dynamics routines in case the user wishes
  185.    to stick to the same conventions as the internal routines.
  186.    Alternatively the user can ignore the internal conventions and
  187.    instead use any parameter in any column of the current schedule;
  188.    a pointer to the entire schedule is stored in the layer field "lrs_p".
  189.    For example, the user may want to eschew the conventions in cases where
  190.    a paradigm has more recall parameters than a single column can hold;
  191.    or in cases where parameters in the same row of a schedule are
  192.    interpolated to give smoother behavior.
  193. */
  194.      
  195. typedef struct {
  196.    Str16 rcntrtxt;                 /* Recall counter text */
  197.    Str16 rcoeftxt[SC_COEFS];       /* Recall coeff text */
  198.    Str16 lcntrtxt;                 /* learn counter text */
  199.    Str16 lcoeftxt[SC_COEFS];       /* Learn coeff text */
  200.    USR_SC_COL  lrs_col[SC_NCOLS];  /* Columns */
  201. } USR_SCHED;
  202.  
  203. /************************************************************************/
  204. /*                                                                      */
  205. /*  Connection Definitions                                              */
  206. /*                                                                      */
  207. /************************************************************************/
  208. /* The following structure refers to the storage associated with a
  209.    single connection.  The items "weight" and "last_dw" hold the values
  210.    that can be viewed in the destination processing element dialog box.
  211.    The source PE is pointed to in "src_pe".  The various bits of "flag"
  212.    are set through the NeuralWorks menu system when creating or modifying
  213.    connections; most of them correspond to the toggle buttons seen in any
  214.    of the Connect Dialog Boxes.  "CN_DISABLED" is used to flag a connection
  215.    which has been disabled on creation or at a later time.  "CN_USER"
  216.    is provided as a bit which can be used exclusively within a user routine.
  217. */
  218.  
  219. typedef struct {            /*   User version of connection structure */
  220.    UW  flag;                 /*   flags for the weight: */
  221.  
  222. #define CN_VAR      0x0000  /*   variable (teachable) weight */
  223. #define CN_FIX      0x0001  /*   fixed weight (does not learn) */
  224. #define CN_SET      0x0002  /*   "set" weight (interacts with iclamp) */
  225. #define CN_MOD      0x0003  /*   "mod" weight (interacts with modf) */
  226. #define CN_WT_MASK  0x0003  /*   mask for weight types */
  227.  
  228. #define CN_ABS      0x0000  /*   absolute connection */
  229. #define CN_REL      0x0004  /*   relative connection */
  230. #define CN_LOC      0x0008  /*   local connection */
  231. #define CN_CN_MASK  0x000c  /*   mask for connections */
  232.  
  233. #define CN_DISABLED 0x0020  /*   connection is "disabled" */
  234. #define CN_PREDIS   0x0010  /*   connection is "pre-disabled" */
  235. #define CN_HIDE     0x8000  /*   hide the connection */
  236.  
  237. #define CN_USER     0x0080  /*   user connection bit */
  238.  
  239.    struct _usr_pe *src_pe;  /*   pointer to source PE */
  240.    /* NOTE: all instances of the USR_CONN structure are generated
  241.       dynamically. The actual number of weight fields allocated per
  242.       connection depends on the the n_wt_flds field in the USR_LYR
  243.       structure. Only the first weight field is absolutely guaranteed to
  244.       be present. The default number of weight fields is 2 but this can be
  245.       over-ridden by either an InstaNet script or by the user when adding
  246.       a layer. */
  247.    SREAL weights[1];        /* weights */
  248. #define weight  weights[0]  /* weighting factor */
  249. #define last_dw weights[1]  /* last delta weight */
  250. } USR_CONN;
  251.  
  252. #if defined(RS6) || defined(IBP) || defined(I860) || defined(XTM) || defined(THINK_C) || defined(__STDC__) || defined(EWS) || defined(VAXULT) || defined(VMS) || defined(IRIS)
  253. /* --- Required for ANSI standard compilers --- */
  254. #define UPDWXP(wxp,SzWts) (wxp = (USR_CONN *)((XB *)wxp + SzWts))
  255. #define UPDRCP(wxp,SzWts) (wxp = (RCON *)((XB *)wxp + SzWts))
  256. #else
  257. /* --- Faster code generated for non-standard ANSI compilers --- */
  258. #define UPDWXP(wxp,SzWts) ((XB *)wxp += SzWts)
  259. #define UPDRCP(wxp,SzWts) ((XB *)wxp += SzWts)
  260. #endif
  261.  
  262. /************************************************************************
  263.    The following structure is the header for the table of connections
  264.    to a destination PE.  Each user defined neuro-dynamics routine is
  265.    passed a pointer to the current PE together with its associated
  266.    connection header (U_CN_HDR structure).  Individual connections can
  267.    be accessed through "conn_table".  "num_conns" gives the actual
  268.    number of connections with the given PE as destination.
  269. */
  270. #define PENL  9                 /*    PE Name Length */
  271. #define PENALC  (PENL+1)        /*    Amount to allocate */
  272.  
  273. typedef struct {                /* Connection header */
  274.    UW     SHIELD(num_alc);      /*    PRIVATE */
  275.    UW     num_conns;            /*    # of actual connections */
  276.    VOID  *ShWtPE;               /*    shared weight ref */
  277.    char   PE_Name[L4A(PENALC)]; /*    PRIVATE */
  278.    USR_CONN conn_table[1];      /*    array of connections */
  279. } USR_CN_HDR;
  280.  
  281. /*   */
  282.  
  283. /************************************************************************
  284.  *                                                                      *
  285.  *  Virtual Memory Support                                              *
  286.  *                                                                      *
  287.  ************************************************************************
  288.  */
  289.  
  290. #ifdef TRANS
  291. typedef unsigned long   WAP;               /* transputer mode */
  292. #define WAPX2REAL(x)    WAP2Real((x))      /* convert it to real */
  293. #define WAPLOCK(x)      TRLockWAP((x))     /* lock a virtual pointer */
  294. #define WAPUNLOCK(x)    TRUnLockWAP((x))   /* unlock a virtual pointer */
  295. #define WAPFLUSH(x)     WAPFlush((x))      /* flush the buffer back to trans */
  296. #else
  297. #ifdef VIRTUAL
  298. /* in virtual mode, the weight array pointer is an offset.  The offset
  299.    is converted to a "real" pointer by the WAP2REAL() macro.
  300. */
  301. typedef unsigned long   WAP;               /* virtual mode */
  302. #define WAPX2REAL(x)    WAP2Real((x))      /* convert it to real */
  303. #define WAPLOCK(x)      WAPlock((x))       /* lock a virtual pointer */
  304. #define WAPUNLOCK(x)    WAPunlock((x))     /* unlock a virtual pointer */
  305. #define WAPFLUSH(x)                        /* ignore it */
  306. #else
  307. /* in real mode, the weight array pointer is just that.  The offset
  308.    does NOT need to be converted, so WAP2REAL() macro just passes it back.
  309. */
  310. typedef USR_CN_HDR     *WAP;               /* non-virtual mode */
  311. #define WAPX2REAL(x)    (x)                /* use it as is */
  312. #define WAPLOCK(x)                         /* lock becomes nothing */
  313. #define WAPUNLOCK(x)                       /* unlock becomes nothing */
  314. #define WAPFLUSH(x)                        /* ignore it */
  315. #endif  /* VIRTUAL */
  316. #endif  /* TRANS */
  317.  
  318. #ifdef TRANS_PHYS
  319.  
  320. #define NEWX(p)   (Xnew[WORD(p)])   /* current output */
  321. #define PPTR(p)   (Xptr[WORD(p)])   /* point to the PE */
  322. #define CERR(p)   (Xerr[WORD(p)])   /* error */
  323. #define LAYX(p)   (Xlay[WORD(p)])   /* layer index */
  324. #undef  WAPX2REAL       /* re-define for NCUBE */
  325. #define WAPX2REAL(p)  (p)     /* real ptrs on NCUBE side */
  326. #else /* TRANS_PHYS */
  327. #define NEWX(p)   ((p)->out_val)    /* current ouptut */
  328. #define CERR(p)   ((p)->err_val)  /* error */
  329. #define PPTR(p)   (p)     /* point to the pe */
  330. #define LAYX(p)   ((p)->io_layerx)  /* layer index */
  331. #endif  /* TRANS_PHYS */
  332.  
  333.  
  334. /************************************************************************/
  335. /*                                                                      */
  336. /*  Processing Element Definitions                                      */
  337. /*                                                                      */
  338. /************************************************************************/
  339.  
  340. /* The following structure refers to the storage associated with an
  341.    individual processing element ( except for the connection header ).
  342.    The SREAL values can all be viewed in the Processing Element/Edit
  343.    dialog box in NeuralWorks.  PEs belonging to a given layer form a
  344.    linked list; "pe_next" points to the next PE in that list.  The head
  345.    of the linked list for the currently processed layer is pointed to
  346.    by (USR_LYR *) ulp->l_ep .  The bits of "flag" are set and used 
  347.    internally by NeuralWorks and should be changed with caution:
  348. */
  349.  
  350. /* Some forward references */
  351. typedef struct _usr_pe  *USR_PE_p;
  352. typedef struct _usr_lyr *USR_LYR_p;
  353.  
  354. #define USER_PROTO(a) NINT a ARGLIST((USR_PE_p, USR_CN_HDR *, USR_LYR_p))
  355.  
  356. typedef struct _usr_pe {        /* PE structure */
  357.    USR_PE_p   pe_next;          /*  4  pointer to next pe in chain */
  358.    UB   SHIELD(io_dummy1);      /*  1 Dummy byte (old flags) */
  359.    UB   SHIELD(io_layerx);      /*  1 index into layer table for owner */
  360.    UW   SHIELD(io_penum);       /*  2 number of this PE (w/in layer) */
  361. #ifdef TRANS_PHYS
  362.    SL   SHIELD(io_ordinal);     /*  4 actual ordinal of PE */
  363. #endif
  364.    SREAL  out_val;              /*  4 Output Value */
  365.    SREAL  sum_val;              /*  4 Summation Value */
  366.    SREAL  trn_val;              /*  4 Transformed Value */
  367.    SREAL  cer_val;              /*  4 Cum Error Value */
  368.    SREAL  err_val;              /*  4 Error Value */
  369.    SREAL  err_fac;              /*  4 Error Factor */
  370.    SREAL  des_val;              /*  4 Desired Output Value (cnf mtx) */
  371.    WAP  SHIELD(io_wtoff);       /*  4 offset / pointer to weight array */
  372.    UW   flag;                   /*  2 flag word */
  373. #define PE_NOT_LEARNED  0x0001  /*    PE has never learned */
  374. #define PE_DISABLED     0x0002  /*    PE is disabled !! */
  375. #define PE_DLTD         0x0004  /*    pe is deleted (unused) */
  376. #define PE_DSPDISAB     0x0008  /*    PE Display disabled */
  377. #define PE_NO_IN_CN     0x0010  /*    PE has NO connections to it */
  378. #define PE_NO_OUT_CN    0x0020  /*    PE has not connections from it */
  379. #define PE_LASTPE       0x0040  /*    Last PE in a chain */
  380. #define PE_ALLVAR       0x0080  /*    All connections are variable */
  381. #define PE_VARFIX       0x0100  /*    Variable & Fixed weights */
  382. #define PE_LEARN_OFF    0x0200  /*    disable learning / competition this PE */
  383. #define PE_VARFIXDIS    0x0400  /*    Variable, Fixed, Diabled weights */
  384. #define PE_WTNOINCN     0x0800  /*    No input conns to source PEs */
  385. #define PE_NEWLY_LRND   0x1000  /*    For competitive learning,
  386.                                       PE has just learned for first time */
  387. #define PE_HIDE         0x8000  /*    hide PEs weights */
  388.  
  389.    UW   SHIELD(io_dummy2);      /*  2 dummy area */
  390.  
  391. #ifdef C_ON_FLY                 /* "Compile on the Fly" */
  392.    USER_PROTO((*pef_sum));      /*  4 Ptr to run time compiled summation */
  393.    USER_PROTO((*pef_backp));    /*  4 Ptr to run time compiled back-prop */
  394.    USER_PROTO((*pef_learn));    /*  4 Ptr to run time compiled delta rule */
  395.    UW            FastFlags;     /*  2 in-line code flags */
  396. #define FAST_SUM        0x0001  /*    in-line summation function */
  397. #define FAST_BACK       0x0002  /*    in-line back-propagation */
  398. #define FAST_LEARN      0x0004  /*    in-line learning rule */
  399. #define FAST_WTS        0x0008  /*    in-line weights */
  400.    UW            FastCount;     /* # of items per math block */
  401.    SREAL        *FastWts;       /* pointer to weight blocks (1/wt component) */
  402. #endif
  403. } USR_PE;
  404.  
  405. typedef struct _usr_pe PE;    
  406.  
  407. /************************************************************************/
  408. /*                                                                      */
  409. /*  Layer Definitions                                                   */
  410. /*                                                                      */
  411. /************************************************************************/
  412. /* The following structure refers primarily to a layer of the network; it
  413.    can also be used to access global network parameters as viewed in the
  414.    network dialog box.  
  415.  
  416.    A global pointer (um_net), sometimes refered to as the super-layer,
  417.    is set up before any user routine is called; it is provided to access 
  418.    network parameters. um_net is a pointer to a USR_LYR structure.
  419.  
  420.    The meaning of each field is now described; typically, layer fields 
  421.    should not be written to from a user routine but should be used for 
  422.    information only.
  423.      
  424.    um_net:
  425.      num_pes: Number of layers in the network
  426.      sum_f: Not Currently Used
  427.      tran_f:  Not Currently Used
  428.      output_f:  Not Currently Used
  429.      learn_f: Not Currently Used
  430.      l_col_x: Not Relevant
  431.      r_col_x: Not Relevant
  432.      lrs_p: Pointer to global network LR Schedule ( Network Edit
  433.             Dialog Box )
  434.      r_col_p: Not Relevant
  435.      l_col_p: Not Relevant
  436.      counters:  Network Counters as viewed in the Network Edit Dialog Box.
  437.        counters[CTR_RECALL]:  Current Recall Count ( set by
  438.           control strategy )
  439.        counters[CTR_LAYER]: Current Layer number (set by
  440.           control strategy )
  441.        counters[CTR_LEARN]: Current Learn Count (incremented
  442.                 each time a learn is done)
  443.        counters[CTR_AUX1]:  Aux 1 parameter - used to define
  444.           an Epoch for Cumulative Delta
  445.           Rule and for Instruments
  446.        counters[CTR_AUX2]:  Aux 2 parameter
  447.        counters[CTR_AUX3]:  Aux 3 parameter
  448.        counters[CTR_WRK1] and counters[CTR_WRK2] are not accessible
  449.        through the Network Edit Dialog Box but can interact with the
  450.        control strategy - see documentation on loadable control
  451.        strategies for more on this.
  452.      *pe_kcur:  Not Currently Used
  453.      val_kcur:  Not Currently Used
  454.      *pe_knext: Not Currently Used
  455.      val_knext: Not Currently Used
  456.      scale: Private Use
  457.      offset:  Private Use
  458.      low_clamp: Private Use
  459.      high_clamp: Private Use
  460.      fprime_off: Not Currently Used
  461.      low_init:  Not Currently Used
  462.      high_init: Not Currently Used
  463.  
  464.    When a user-defined function is called, one of its arguments is the
  465.    current layer (ulp), a pointer to the USR_LYR structure corresponding
  466.    to the current layer.
  467.  
  468.    ulp:
  469.      num_pes: Number of PEs in the layer
  470.      sum_f: Summation function for layer  ( Layer Edit Dialog Box )
  471.      tran_f:  Transfer function for layer ( Layer Edit Dialog Box )
  472.      output_f:  Output function for layer ( Layer Edit Dialog Box )
  473.      learn_f: Learn function for layer  ( Layer Edit Dialog Box )
  474.      noise_f: Noise function for layer  ( Layer Edit Dialog Box )
  475.      l_col_x: Index of current learn column of the layer LR Schedule
  476.      r_col_x: Index of current recall column of the layer LR Schedule
  477.      lrs_p: Pointer to layer LR Schedule  ( Layer Edit Dialog Box )
  478.      r_col_p: Pointer to current recall column in layer LR Schedule
  479.      l_col_p: Pointer to current learn column in layer LR Schedule
  480.      counters:
  481.        counters[CTR_RECALL]:  RESERVED
  482.        counters[CTR_LAYER]: RESERVED
  483.        counters[CTR_LEARN]: RESERVED
  484.        counters[CTR_AUX1]:  RESERVED
  485.        counters[CTR_AUX2]:  RESERVED
  486.        counters[CTR_AUX3]:  RESERVED
  487.        counters[CTR_WRK1]:  Available for user use
  488.        counters[CTR_WRK2]:  Available for user use
  489.        
  490.      *pe_kcur:  Kohonen winner. Can be used in user competitive functions
  491.      val_kcur:  Value of Kohonen winner
  492.      *pe_knext: Next winner. Can be used in user competitive functions
  493.      val_knext: Value of next winner
  494.      scale: Output multiplier (scale) ( Layer Edit Dialog Box )
  495.      offset:  Output offset     ( Layer Edit Dialog Box )
  496.      low_clamp: Output low clamp    ( Layer Edit Dialog Box )
  497.      high_clamp: Output high clamp    ( Layer Edit Dialog Box )
  498.      fprime_off: Offset for F'      ( Layer Edit Dialog Box )
  499.      low_init:  Low limit of init range   ( Layer Edit Dialog Box )
  500.      high_init: high limit of init range  ( Layer Edit Dialog Box )
  501.  
  502. */
  503.  
  504. /*
  505.    The NW_GRAPHIC structure is used within NeuralWorks to define the 
  506.    graphical look of the layers and screen. All it's contents should be
  507.    considered private and never referred to or changed.
  508. */
  509.  
  510. typedef SW COMPONENT;
  511.  
  512. typedef struct {
  513.    SW   sg_x;    /* signed graphic x-coordinate */
  514.    SW   sg_y;    /* signed graphic y-coordinate */
  515. } SWC;
  516.  
  517. typedef struct {
  518.    UW   ug_x;    /* unsigned graphic x-coordinate */
  519.    UW   ug_y;    /* unsigned graphic y-coordinate */
  520. } UWC;
  521.  
  522. typedef long      GCOORD;       /* graphic coordinate */
  523. typedef COMPONENT SCREEN_COORD; /* graphic coordinate for screen*/
  524.  
  525. #ifdef I860
  526. GLOBALREF SW *i860swptr;
  527. #define SGX(c)  (*(i860swptr = ((SW *)(&(c)))))
  528. #define SGY(c)  (*((i860swptr = ((SW *)(&(c))))+1))
  529. #else
  530. #define SGX(c)  (((SWC *)(&(c)))->sg_x) /* signed x-coordinate */
  531. #define SGY(c)  (((SWC *)(&(c)))->sg_y) /* signed y-coordinate */
  532. #endif
  533.  
  534. #define UGX(c)  (((UWC *)(&(c)))->ug_x) /* unsigned x-coordinate */
  535. #define UGY(c)  (((UWC *)(&(c)))->ug_y) /* unsinged y-coordinate */
  536.  
  537. /* --- Layer Display --- */
  538.  
  539. #define G_NAM_LEN 10         /* length of layer name */
  540. typedef struct {
  541.    GCOORD   g_cgp;           /*  4 current screen position */
  542.    NINT     g_cgz[2];        /*  4/8 current screen position as array */
  543.    UW       g_nrws;          /*  2 number of rows */
  544.    UW       g_cgs;           /*  2 current screen spacing */
  545.  
  546.    GCOORD   g_nt;            /*  4 base coordinate of layer */
  547.    GCOORD   g_hw;            /*  4 base psn for hinton weight diagram */
  548.    GCOORD   g_ha;            /*  4 base coordinate of layer for activation */
  549.    GCOORD   g_io;            /*  4 offset for input terminal (signed) */
  550.    GCOORD   g_oo;            /*  4 offset for output terminal (signed) */
  551.    UB       g_disp;          /*  1 display mode */
  552. #define GD_NETWORK    0      /*    display as a network */
  553. #define GD_HINTON     1      /*    display as a hinton diagram */
  554. #define GD_TITLE      3      /*    title page */
  555.    UB       g_spacing;       /*  1 spacing */
  556.    UB       g_shape;         /*  1 display shape */
  557. #define SH_SQUARE 0          /*    square */
  558. #define SH_TRIANGLE 1        /*    triangle */
  559. #define SH_CIRCLE 2          /*    circle */
  560.    XB       g_name[L4A(G_NAM_LEN+1)]; /* 11 layer name */
  561. } NW_GRAPHIC;     /* 46 total length */
  562.  
  563. /* --- Layer extensions;  these are set up and used at the start of and
  564.    during execution of a network */
  565.  
  566. typedef struct _lyr_ext {    /* pointers to functions */
  567.    USER_PROTO((*sum));
  568.    USER_PROTO((*tran));
  569.    USER_PROTO((*output));
  570.    USER_PROTO((*learn));
  571.    USER_PROTO((*error));
  572.    USER_PROTO((*noise));
  573.    UW    fls_flag;           /* flag used by fl_sum */
  574.    UL    cycle_mask;
  575.    UW    size_wts;           /* size of weight array */
  576.    UW    iox_flags;          /* I/O execution flags */
  577. #define IOX_ERR    0x0001    /* I/O error */
  578. #define IOX_TERM   0x0002    /* Request to terminate I/O */
  579. #define IOX_NOW    0x0004    /* Now Mode */
  580. #define IOX_AUTOT  0x0008    /* Automated Test Mode */
  581. #define IOX_LEARN  0x0010    /* Learn Mode */
  582. #define IOX_RECALL 0x0020    /* Recall Mode */
  583. #define IOX_TEST   0x0040    /* Test Mode */
  584. #define IOX_EXPLN  0x0080    /* Explain Mode */
  585. #define IOX_INTRPT 0x0100    /* Execution interrupted */
  586. #define IOX_REINFSTRT 0x0200  /* Start of reinforcement pass */
  587. #define IOX_REDO   0x0400    /* Redo start of reinforcement pass */
  588. #define IOX_CASCMODE 0x0800  /* Cascade mode learning */
  589. } LYR_EXT;
  590.  
  591. /************************************************************************
  592.  *                                                                      *
  593.  *  Layer / Super-Layer Structure                                       *
  594.  *                                                                      *
  595.  ************************************************************************
  596.  NOTE:  the "OFF_xxxx" defines are used in the HDIR structures to
  597.  define where the following field is with respect to the start of a
  598.  layer structure.  Thus, it is VERY important that these values are
  599.  properly updated if the structure is changed in any way.
  600.  */
  601.  
  602. #define MAX_LAYERS  50    /* max layers to work with */
  603.  
  604. typedef VOID *PELP;
  605.  
  606. typedef struct _usr_lyr {                       /* layer structure */
  607.    USR_LYR_p         SHIELD(l_next);    /*  4 next layer at this level */
  608.    USR_LYR_p         SHIELD(l_prev);    /*  4 previous layer at this level */
  609.    USR_LYR_p         SHIELD(l_owner);   /*  4 pointer to owner layer */
  610.    PELP              SHIELD(l_ep);      /*  4 element pointer */
  611.    UW                num_pes;           /*  2 # of pe's in the layer or
  612.                                             # of layers in network */
  613.    UW                n_wt_flds;         /*  2 wght fields per connection */
  614.    UW                SHIELD(l_selfx);   /*  2 PRIVATE */
  615.    UW                flag;              /*  2 Layer Flags */
  616. #define LF_NESTEDS     0x0001           /*    nested super-layers below this */
  617. #define LF_LEAF        0x0002           /*    this is a leaf node(only pe's)*/
  618. #define LF_EORS        0x0004           /*    end of recall schedule */
  619. #define LF_UEORS       0x0020           /*    user end of recall */
  620. #define LF_EOLS        0x0008           /*    end of learn schedule */
  621. #define LF_AUTOASSOC   0x0080           /*    autoassociative */
  622. #define LF_SELFCONN    0x0010           /*    layer is self-connected */
  623. #define LF_REINFORC    0x0040           /*    reinforcement learning */
  624. #define LF_INSTANET    0x0200           /*    network created using InstaNet */
  625. #define LF_PRJCTION    0x0400           /*    projection network or layer */
  626. #define LF_CASCCORR    0x0800           /*    cascade correlation network */
  627. #define LF_FMT2File    0x0100           /*    format 2 file */
  628. #define LF_REORG       0x4000           /*    net needs to be reorganized */
  629. #define LF_HIDE        0x8000           /*    hide layer's weights */
  630. #define LF_FMT3File    0x10000l         /*    format 3 file (new IO stuff) */
  631. #define LF_FMT4File    0x20000l         /*    format 4 file (aux wght field) */
  632. #define LF_FMT5File    0x40000l         /*    format 5 file (load net) */
  633. #define LF_FMT6File    0x80000l         /*    format 6 file (load net) */
  634. #define LF_FMT7File    0x100000l        /*    format 7 file (load net) */
  635.  
  636.    UW                SHIELD(l_lrnio);   /*  2 Learn I/O options flag */
  637.    UW                SHIELD(l_rclio);   /*  2 Recall/Test I/O options flag */
  638. #define LIO_ALPHA      1                /*    alpha learn files */
  639. #define LIO_FSEQ       LIO_ALPHA        /*    file sequential */
  640. #define LIO_KEY        2                /*    keyboard learn input */
  641. #define LIO_FRAND      3                /*    file random */
  642. #define LIO_MASK       0x000f           /*    option mask */
  643.  
  644. #define LIO_INP        0x0010           /*    include input in result file */
  645. #define LIO_DES        0x0020           /*    include desired output */
  646. #define LIO_BINARY     0x0040           /*    attempt to use/create binary */
  647. #define LIO_USER       0x0080           /*    user defined learn function */
  648. #define LIO_FAF        0x0100           /*    Fast Ascii (Load file) */
  649. #define LIO_APPEND     0x0200           /*    Append to result file */
  650. #define LIO_HEADER     0x0400           /*    Include header in result file */
  651. #define LIO_UIOOBJF    0x0800           /*    Objctv. func. is a user func. */
  652.  
  653.    UB                SHIELD(l_dummy1);  /*  1 PRIVATE */
  654.    
  655.    UB                SHIELD(l_cntrlx);  /*  1 Cntrl Strat idx (Explorer) */
  656. #define LC_DEFAULT     0                /*    default Control Strategy (BP) */
  657. #define LC_ADALINE     1                /*    adaline / madaline */
  658. #define LC_PERCEPTRON  2                /*    perceptron */
  659. #define LC_BACKPROP    3                /*    back-propagation */
  660. #define LC_COUNTERPROP 4                /*    counter-propagation */
  661. #define LC_HOPFIELD    5                /*    hopfield CAN/BSB/BSB-WH */
  662. #define LC_BAM         6                /*    bam */
  663. #define LC_TSP         7                /*    Traveling-Saleman Problem */
  664.  
  665.    UB                SHIELD(l_style);   /*  1 Style Index */
  666.  
  667.    UB                sum_f;             /*    summation function index */
  668. #define LS_SUM         1                /*    sum of weighted products */
  669. #define LS_ISUM        2                /*    "incremental" weighted sum */
  670. #define LS_MAX         3                /*    "max" of weighted prod */
  671. #define LS_MIN         4                /*    "min" of weighted prod */
  672. #define LS_MAJ         5                /*    "majority" */
  673. #define LS_NORMN       6                /*    "norm" of n+1 unit vectors */
  674. #define LS_NORM1       7                /*    "norm" of unit vector */
  675. #define LS_PROD        8                /*    product of weighted inputs */
  676. #define LS_NORMS       9                /*    "norm" to scale factor */
  677. #define LS_NORMP      10                /*    "polar" norm */
  678. #define LS_NORMM      11                /*    "multiplicative" norm */
  679. #define LS_CITYBLK    12                /*    City Block */
  680. #define LS_SPR        13                /*    SPR */
  681. #define LS_DNNA       14                /*    DNNA summation function */
  682. #define LS_SOM        15                /*    Self Organizing Map */
  683. /* 16 is a user summation function */
  684. #define LS_LVQ        17                /*    Linear Vector Quantization */
  685. #define LS_CASCADE    18                /*    Cascade Correlation */
  686. #define LS_EUCLID     19                /*    Euclidean Distance */
  687. #define LS_NORMCP     21                /*    Central Projection Norm */
  688. #define LS_FZART      22                /*    Fuzzy ART */
  689. #define LS_USER1    0x10                /*    User Summation 1 */
  690. #define LS_USER2    0x20                /*    User Summation 2 */
  691. #define LS_USER3    0x30                /*    User Summation 3 */
  692. #define LS_USER4    0x40                /*    User Summation 4 */
  693. #define LS_USER5    0x50                /*    User Summation 5 */
  694. #define LS_USER6    0x60                /*    User Summation 6 */
  695. #define LS_USER7    0x70                /*    User Summation 7 */
  696. #define LS_USER8    0x41                /*    User Summation 8 */
  697. #define LS_USER9    0x42                /*    User Summation 9 */
  698. #define LS_USERA    0x43                /*    User Summation A */
  699. #define LS_USERB    0x44                /*    User Summation B */
  700. #define LS_USERC    0x45                /*    User Summation C */
  701. #define LS_USERD    0x46                /*    User Summation E */
  702. #define LS_USERE    0x47                /*    User Summation F */
  703. #define LS_USERF    0x48                /*    User Summation G */
  704. #define LS_UMASK    0x70                /*    User Summation Mask */
  705.  
  706.    UB                tran_f;            /*  1 transfer function index */
  707. #define LT_LINEAR      1                /*    F(k) = k */
  708. #define LT_PERCEPTRON  2                /*    F(k) = 0, k<=0;  k, k>0 */
  709. #define LT_BSB         3                /*    F(k) = -l,k<-l;+h,k>h;else k*/
  710. #define LT_SIGMOID     4                /*    F(k) = 1/(1+e**(-k)) */
  711. #define LT_TANH        5                /*    F(k) = 0.5 * ( 1 + tanh(k) ) */
  712. #define LT_SINE        6                /*    F(k) = sine(k) */
  713. #define LT_SGN         7                /*    F(k) = -1,k<0;+1,k>=0 */
  714. #define LT_SGN0        8                /*    F(k) = -1,k<0;0,k=0;+1,k>0 */
  715. #define LT_STEPF       9                /*    F(k) = 0,k<=0;1,k>0 */
  716. #define LT_PSI        10                /*    F(k) = -1,k<0;old k,k=0;1,k>0*/
  717. #define LT_SPR        11                /*    F(k) = SPR */
  718. #define LT_DNNA       12                /*    F(k) = DNNA transfer function */
  719. #define LT_DNNA_SGM   13                /*    F(k) = DNNA Sigmoid trans. fn*/
  720. #define LT_EXP        14                /*    Exponential func. (no deriv) */
  721. #define LT_RADBAS     15                /*    Radial Basis */
  722. /* 16 is a user function */
  723. #define LT_PNN        17                /*    PNN */
  724. #define LT_BOLTZ      18                /*    Boltzmann */
  725. #define LT_GRNN       19                /*    General Regression Network */
  726. #define LT_USER1    0x10                /*    User Transfer 1 */
  727. #define LT_USER2    0x20                /*    User Transfer 2 */
  728. #define LT_USER3    0x30                /*    User Transfer 3 */
  729. #define LT_USER4    0x40                /*    User Transfer 4 */
  730. #define LT_USER5    0x50                /*    User Transfer 5 */
  731. #define LT_USER6    0x60                /*    User Transfer 6 */
  732. #define LT_USER7    0x70                /*    User Transfer 7 */
  733. #define LT_USER8    0x41                /*    User Transfer 8 */
  734. #define LT_USER9    0x42                /*    User Transfer 9 */
  735. #define LT_USERA    0x43                /*    User Transfer A */
  736. #define LT_USERB    0x44                /*    User Transfer B */
  737. #define LT_USERC    0x45                /*    User Transfer C */
  738. #define LT_USERD    0x46                /*    User Transfer E */
  739. #define LT_USERE    0x47                /*    User Transfer F */
  740. #define LT_USERF    0x48                /*    User Transfer G */
  741. #define LT_UMASK    0x70                /*    User Tran. Function Mask */
  742.  
  743.    UB                output_f;          /*  1 output (update) function index */
  744. #define LU_ALL      0x00                /*    no competition ( direct ) */
  745. #define LU_COMP     0x01                /*    competitive one winner */
  746. #define LU_FZART    0x11                /*    Fuzzy ARTMap, competitive
  747.                                               + other stuff */
  748. #define LU_SELECT   0x21                /*    Direct Output, but selects
  749.                                               winner for learning. */
  750. #define LU_COMP2    0x02                /*    competitive, two winners */
  751. #define LU_ACT      0x80                /*    only active PEs compete */
  752. #define LU_COMPACT  (LU_COMP|LU_ACT)    /*    competitive, 1 highest active */
  753. #define LU_COMPACT2 (LU_COMP2|LU_ACT)   /*    competitive, 2 highest active */
  754. #define LU_ADALINE  0x04                /*    adaline competition */
  755. #define LU_SPR      0x08                /*    spr competition */
  756. #define LU_DNNA     0x14                /*    dnna output - non-competitive */
  757. #define LU_FZARTMAP 0x18                /*    ARTMap output layer */
  758. #define LU_LVQ      0x24                /*    Linear Vector Quantization */
  759. #define LU_SOM      0x28                /*    Self Organizing Map */
  760. #define LU_NORM     0x34                /*    Normalized outputs */
  761. #define LU_MODNNGT  0x38                /*    Modular NN gating output */
  762. #define LU_DIVIDE   0x54                /*    Divide by first PEs */
  763. #define LU_SOFTMAX  0x58                /*    SoftMax exp(I)/SUM(exp(I)) */
  764. #define LU_USER1    0x10                /*    User Output 1 */
  765. #define LU_USER2    0x20                /*    User Output 2 */
  766. #define LU_USER3    0x30                /*    User Output 3 */
  767. #define LU_USER4    0x40                /*    User Output 4 */
  768. #define LU_USER5    0x50                /*    User Output 5 */
  769. #define LU_USER6    0x60                /*    User Output 6 */
  770. #define LU_USER7    0x70                /*    User Output 7 */
  771. #define LU_USER8    0x41                /*    User Output 8 */
  772. #define LU_USER9    0x42                /*    User Output 9 */
  773. #define LU_USERA    0x43                /*    User Output A */
  774. #define LU_USERB    0x44                /*    User Output B */
  775. #define LU_USERC    0x45                /*    User Output C */
  776. #define LU_USERD    0x46                /*    User Output E */
  777. #define LU_USERE    0x47                /*    User Output F */
  778. #define LU_USERF    0x48                /*    User Output G */
  779. #define LU_UMASK    0x70                /*    User Output Function Mask */
  780.  
  781.    UB                learn_f;           /*  1 learn function index */
  782. #define LL_NONE     0x00                /*    fanout - no learning */
  783. #define LL_HEBB     0x01                /*    hebbian */
  784. #define LL_HEBBANTI 0x02                /*    hebb / anti-hebbian */
  785. #define LL_HOPFIELD 0x03                /*    hopfield */
  786. #define LL_BSB_WH   0x04                /*    bsb Widrow-Hoff */
  787. #define LL_BSB_HOPF 0x05                /*    bsb hopfield learning */
  788. #define LL_WIDHOFF  0x06                /*    widrow-hoff (CPN) */
  789. #define LL_KOHONEN  0x07                /*    kohonen learning */
  790. #define LL_KOHONEN1 0x08                /*    kohonen - post normalize to 1 */
  791. #define LL_KOHONENN 0x09                /*    kohonen - post normalize to n */
  792. #define LL_GDELTA   0x0a                /*    generalized delta rule */
  793. #define LL_ADALINE  0x0b                /*    ADALINE learning */
  794. #define LL_PERCEPTRON 0x0c              /*    perceptron learning */
  795. #define LL_CUMGDELTA  0x0d              /*    cumulative generalized delta */
  796. #define LL_SPR      0x0e                /*    SPR learning rule */
  797. #define LL_ART1     0x0f                /*    ART 1 learning rule */
  798. #define LL_NORMCUMD 0x11                /*    Normalized cum delta */
  799. #define LL_EDBD     0x12                /*    Extended Delta Bar Delta */
  800. #define LL_DBD      0x13                /*    Delta Bar Delta */
  801. #define LL_DRS      0x14                /*    Directed Random Search */
  802. #define LL_SOM      0x15                /*    Self-Organizing Map */
  803. /* 16 is a user learn function */
  804. #define LL_LVQ      0x17                /*    Linear Vector Quantization */
  805. #define LL_GENETIC  0x18                /*    Genetic Reinforcement Learning */
  806. #define LL_GRCNTRL  0x19                /*    Genetic Reinforcement Control */
  807. #define LL_FZART    0x1a                /*    Fuzzy ARTMAP */
  808. #define LL_PROJNN   0x1b                /*    Projective delta rule */
  809. #define LL_KMEANS   0x1c                /*    Use for Euclidean, City block
  810.                                               or Projective Kohonen learning.
  811.                                               If source layer is projective,
  812.                                               will project to radius of the
  813.                                               hypersphere */
  814. #define LL_PNN      0x1d                /*    PNN learn function */
  815. #define LL_BOLTZ    0x1e                /*    Boltzmann */
  816. #define    LL_QUICKPROP 0x1f        /*    Quick Prop */
  817. #define    LL_MAXPROP  0x21        /*    Max Prop */
  818. #define LL_GRNN     0x22                /*    GRNN learn function */
  819. #define LL_USER1    0x10                /*    User Learn 1 */
  820. #define LL_USER2    0x20                /*    User Learn 2 */
  821. #define LL_USER3    0x30                /*    User Learn 3 */
  822. #define LL_USER4    0x40                /*    User Learn 4 */
  823. #define LL_USER5    0x50                /*    User Learn 5 */
  824. #define LL_USER6    0x60                /*    User Learn 6 */
  825. #define LL_USER7    0x70                /*    User Learn 7 */
  826. #define LL_USER8    0x41                /*    User Learn 8 */
  827. #define LL_USER9    0x42                /*    User Learn 9 */
  828. #define LL_USERA    0x43                /*    User Learn A */
  829. #define LL_USERB    0x44                /*    User Learn B */
  830. #define LL_USERC    0x45                /*    User Learn C */
  831. #define LL_USERD    0x46                /*    User Learn E */
  832. #define LL_USERE    0x47                /*    User Learn F */
  833. #define LL_USERF    0x48                /*    User Learn G */
  834. #define LL_UMASK    0x70                /*    User Learn Function Mask */
  835.  
  836.    UB                error_f;           /*  1 error function */
  837. #define LE_STANDARD    0                /*    normal error function */
  838. #define LE_QUADRATIC   1                /*    quadratic */
  839. #define LE_CUBIC       2                /*    cubic */
  840. #define LE_TOLERANT    3                /*    tolerant */
  841. #define LE_DRS         4                /*    Directed Random Search */
  842. #define LE_MODNNGT     5                /*    Modular NN Gating error */
  843. #define LE_KNN         6                /*    K Nearest neighbour */
  844. #define LE_SOFTMAX     7                /*    Softmax */
  845. #define LE_CASCADE     8                /*    Cascade error */
  846. #define LE_USER1    0x10                /*    User Error 1 */
  847. #define LE_USER2    0x20                /*    User Error 2 */
  848. #define LE_USER3    0x30                /*    User Error 3 */
  849. #define LE_USER4    0x40                /*    User Error 4 */
  850. #define LE_USER5    0x50                /*    User Error 5 */
  851. #define LE_USER6    0x60                /*    User Error 6 */
  852. #define LE_USER7    0x70                /*    User Error 7 */
  853. #define LE_USER8    0x41                /*    User Error 8 */
  854. #define LE_USER9    0x42                /*    User Error 9 */
  855. #define LE_USERA    0x43                /*    User Error A */
  856. #define LE_USERB    0x44                /*    User Error B */
  857. #define LE_USERC    0x45                /*    User Error C */
  858. #define LE_USERD    0x46                /*    User Error E */
  859. #define LE_USERE    0x47                /*    User Error F */
  860. #define LE_USERF    0x48                /*    User Error G */
  861. #define LE_UMASK    0x70                /*    User Error Function Mask */
  862.  
  863.    UB                noise_f;           /*  1 Noise function (used for
  864.                                             weigt initialization also */
  865. #define LN_UNIFORM     0
  866. #define LN_GAUSSIAN    1
  867. #define LN_NONE        2
  868. #define LN_USER1    0x10                /*    User Noise 1 */
  869. #define LN_USER2    0x20                /*    User Noise 2 */
  870. #define LN_USER3    0x30                /*    User Noise 3 */
  871. #define LN_USER4    0x40                /*    User Noise 4 */
  872. #define LN_USER5    0x50                /*    User Noise 5 */
  873. #define LN_USER6    0x60                /*    User Noise 6 */
  874. #define LN_USER7    0x70                /*    User Noise 7 */
  875. #define LN_USER8    0x41                /*    User Noise 8 */
  876. #define LN_USER9    0x42                /*    User Noise 9 */
  877. #define LN_USERA    0x43                /*    User Noise A */
  878. #define LN_USERB    0x44                /*    User Noise B */
  879. #define LN_USERC    0x45                /*    User Noise C */
  880. #define LN_USERD    0x46                /*    User Noise E */
  881. #define LN_USERE    0x47                /*    User Noise F */
  882. #define LN_USERF    0x48                /*    User Noise G */
  883. #define LN_UMASK    0x70                /*    User Noise Function Mask */
  884.  
  885.    UB  SHIELD(l_lrsched);               /*  1 Schedule index */
  886. #define LRS_DEFAULT    0                /*    default schedule */
  887.  
  888.    UB  SHIELD(l_mmtable);               /*  1 MinMax table index */
  889. #define MMT_DEFAULT    0
  890.    UB                l_col_x;           /*  1 current lrn column in sched */
  891.    UB                r_col_x;           /*  1 current rcl column in sched */
  892. #ifdef C_ON_FLY
  893.    UB                l_col_n;           /*  1 # of cols in learn sched FC2 */
  894.    UB                r_col_n;           /*  1 # of cols in recall sched FC2 */
  895. #endif
  896.    USR_SCHED        *lrs_p;             /*  1 LR Schedule pointer */
  897.    USR_SC_COL       *r_col_p;           /*  1 current recall column ptr */
  898.    USR_SC_COL       *l_col_p;           /*  1 current learn column ptr */
  899.    NW_GRAPHIC        SHIELD(l_dsp);     /* 46 PRIVATE         */
  900.  
  901. #define N_COUNTERS     8                /*    # of counters */
  902.    SL                counters[N_COUNTERS];/* 32   counter array */
  903. #define CTR_RECALL     0                /* recall cycle */
  904. #define CTR_LAYER      1                /* layer number */
  905. #define CTR_LEARN      2                /* learn count */
  906. #define CTR_AUX1       3                /* aux 1 */
  907. #define CTR_AUX2       4                /* aux 2 */
  908. #define CTR_AUX3       5                /* aux 3 */
  909. #define CTR_WRK1       6                /* work 1 */
  910. #define CTR_WRK2       7                /* work 2 */
  911.                                         /* Kohonen -winner information      */
  912. #define l_layer_n counters[CTR_LAYER]   /*    current layer */
  913. #define l_counter counters[CTR_RECALL]  /*    counter (recall cycle) */
  914. #define l_epoch   counters[CTR_LEARN]   /*    learning counter */
  915.  
  916.    USR_PE           *pe_kcur;           /*  4 Current or positive winner */
  917.    SREAL             val_kcur;          /*  4 Value of winner */
  918.    USR_PE           *pe_knext;          /*  4 Next or negative winner */
  919.    SREAL             val_knext;         /*  4 Value of winner */
  920.  
  921.    SREAL             scale;             /*  4 output multiplier (scale) */
  922. #define l_ip_lo      scale              /*    OR input target range low
  923.                                               for super-layer */
  924.    SREAL             offset;            /*  4 output offset */
  925. #define l_ip_hi      offset             /* OR input target range high
  926.                                               for super-layer */
  927.    SREAL             lo_clip;           /*  4 output low clip */
  928. #define l_op_lo      lo_clip            /* OR des. output target range low
  929.                                               for super-layer */
  930.    SREAL             hi_clip;           /*  4 output high clip */
  931. #define l_op_hi      hi_clip            /* OR des. output target range high
  932.                                               for super-layer */
  933.    SREAL             fprime_off;        /*  4 offset for f' */
  934.    SREAL             low_init;          /*  4 low initialization limit */
  935.    SREAL             high_init;         /*  4 high initialization limit */
  936.  
  937.    SREAL             SHIELD(normsum);   /*  4 PRIVATE */
  938.    NINT              SHIELD(l_XecFlags);/*  2/4  PRIVATE */
  939.  
  940. #ifdef C_ON_FLY
  941.    NINT              SHIELD(l_XecMathF); /*    PRIVATE FC2 */
  942.    NINT              SHIELD(l_XecWType); /*    PRIVATE FC2 - weight types */
  943. #define XEC_WTDISAB    0x0001           /*      disabled */
  944. #define XEC_WTVAR      0x0002           /*      variable */
  945. #define XEC_WTSET      0x0004           /*      set-type */
  946. #define XEC_WTMOD      0x0008           /*      mod-type */
  947. #define XEC_WTFIX      0x0010           /*      fixed type */
  948. #define XEC_WTNOINC    0x0020           /*      inputs have no conns */
  949. #define XEC_PEDIS      0x0040           /*      a PE is disabled */
  950. #define XEC_LRNDIS     0x0080           /*      learning disabled */
  951. #define XEC_ZCLAMP     0x0100           /*      LRS Clamp = 0.0 */
  952. #define XEC_ZLNOISE    0x0200           /*      LRS Learn Temp = 0.0 */
  953. #define XEC_ZRNOISE    0x0400           /*      LRS Recall Temp = 0.0 */
  954. #define XEC_FIRE100    0x0800           /*      LRS Fire = 100.0 ! */
  955.  
  956.    /* NOTE: Uses UMCF_XXX flags */
  957. #endif
  958. #ifndef TRANS_PHYS
  959.    char              SHIELD(l_uionam)[FNALC];  /*    PRIVATE */
  960.    char              SHIELD(l_uiolrn)[FNALC];  /*    PRIVATE */
  961.    char              SHIELD(l_uiorcl)[FNALC];  /*    PRIVATE */
  962. #endif /* TRANS_PHYS */
  963.  
  964.    LYR_EXT functions;    /* run-time math pointers and flag */
  965. } USR_LYR;
  966.  
  967. typedef struct _usr_lyr LAYER;
  968.  
  969.  
  970. #define ISUSER(x) ( ((x) & 0x40) || ( (x) && (((x)&0x70) == (x) )) )
  971.  
  972. /*   */
  973. /************************************************************************
  974.  *                                                                      *
  975.  *  MinMax Tables                                                       *
  976.  *                                                                      *
  977.  ************************************************************************
  978.    MinMax tables hold the minimum and maximum values for each column of
  979.    IO.  These tables are typically created from training, test and/or
  980.    master data files throught the MinMax utilities.  These utilities
  981.    provide for MinMax tables to be merged with other tables and files.
  982.    The MinMax utilities should give warnings if an attempt is made to
  983.    merge potentially incompatible tables and/or files but it is ultimately
  984.    up to the user to ensure valid tables.
  985.  
  986.    The set of values in a MinMax table are synchronised with the columns
  987.    in the data file rather than in the network.  The link between the
  988.    file values and the values presented to the network are determined
  989.    by Network IO parameters.
  990.  */
  991.  
  992. typedef struct {
  993.    SREAL mme_min;        /* Minimum of range */
  994.    SREAL mme_max;        /* Maximum of range */
  995. } MMT_ENT;
  996.  
  997. typedef struct {
  998.    SL  mm_nent;          /* Number of entries */
  999.    MMT_ENT mm_ent[1];    /* Table of entries */
  1000. } MMT;
  1001.  
  1002. #ifndef MAXFLOAT
  1003. #define MAXFLOAT  (1.0e35)  /* maximum float value */
  1004. #endif
  1005.  
  1006. #define MMT_MIN_INIT  MAXFLOAT
  1007. #define MMT_MAX_INIT  (-MMT_MIN_INIT)
  1008.  
  1009. /* */
  1010. /************************************************************************/
  1011. /*                                                                      */
  1012. /*  Control Strategy Math Instruction Microcode Bits                    */
  1013. /*                                                                      */
  1014. /************************************************************************/
  1015. /* A control strategy math instruction can be thought of as a microcode
  1016.    instruction where each operation corresponds to a bit in a microcode
  1017.    vector.  Refer to the documentation on User Defined Control Strategies
  1018.    for more information on this.  The global variable "um_micro" (declared
  1019.    below and defined in usermath.c) makes the microcode vector available
  1020.    to the user math routines.  Symbols for each bit are defined below; the
  1021.    corresponding control strategy literal is added as a comment.
  1022. */
  1023. #define MF_SETBIT   0x10000000l /* "setb" */
  1024. #define MF_SETX     0x00000001l /* "o=0" */
  1025. #define MF_SET      0x00001000l /* "set" */
  1026. #define MF_FIRE     0x00002000l /* "fire" */
  1027. #define MF_SUM      0x00004000l /* "sum" */
  1028. #define MF_WEQI     0x00000080l /* "w=i" */
  1029. #define MF_IEQER    0x00000100l /* "i=e" */
  1030. #define MF_CEEQER   0x00000400l /* "ce=e" */
  1031. #define MF_EREQO    0x00000020l /* "e=o" */
  1032. #define MF_WEQER    0x00000040l /* "w=e" */
  1033. #define MF_EREQCE   0x00000800l /* "e=ce" */
  1034. #define MF_LNOISE   0x00008000l /* "lnoise" */
  1035. #define MF_RNOISE   0x00010000l /* "rnoise" */
  1036. #define MF_TRAN     0x00020000l /* "tran" */
  1037. #define MF_OUTPUT   0x00040000l /* "output" */
  1038. #define MF_GATE     0x00080000l /* "gate" */
  1039. #define MF_ERROR    0x00100000l /* "e-=w" */
  1040. #define MF_ERRFAC   0x00000002l /* "e*=ef */
  1041. #define MF_REGRESS  0x40000000l /* "regress" */
  1042. #define MF_OEQTRN   0x00000008l /* "o=w" */
  1043. #define MF_EREQW    0x00200000l /* "e=w" */
  1044. #define MF_IEQWX    0x00000200l /* "i=w" */
  1045. #define MF_ERFPRM   0x00400000l /* "e*=f'" */
  1046. #define MF_COUNTER  0x00800000l /* "cterr" */
  1047. #define MF_SWAP     0x00000004l /* "swap" */
  1048. #define MF_BACKP    0x01000000l /* "backp" */
  1049. #define MF_LEARN    0x02000000l /* "learn" */
  1050. #define MF_SETW     0x04000000l /* "w=0" */
  1051. #define MF_SETE     0x08000000l /* "e=0" */
  1052. #define MF_RESET    0x20000000l /* "reset" */
  1053.  
  1054. /* flags used in math routines */
  1055.  
  1056. #define FLS_FIRE        0x0001  /* check for firing */
  1057. #ifndef C_ON_FLY
  1058. #define FLS_NOISE       0x0002  /* noise (l/r) is not zero */
  1059. #else
  1060. #define FLS_RNOISE      0x0002  /* noise (recall) is not zero */
  1061. #define FLS_LNOISE      0x4000  /* noise (learning) in non-zero */
  1062. #define FLS_NOISE       (FLS_RNOISE|FLS_LNOISE)
  1063. #endif
  1064. #define FLS_COEF3       0x0004  /* LCOEF3 is not zero */ 
  1065. #define FLS_SCALE       0x0008  /* scale only as part of s/o */
  1066. #define FLS_OFFONLY     0x0010  /* offset only as part of scale */
  1067. #define FLS_NORMF       0x0020  /* normalizing layer */
  1068. #define FLS_USR_LEARN   0x0040  /* user learn function */
  1069. #define FLS_USR_SUM     0x0080
  1070. #define FLS_USR_OUT     0x0100
  1071. #define FLS_USR_TRAN    0x0200
  1072. #define FLS_USR_ERROR   0x0400
  1073. #define FLS_CKLIMS      0x0800  /* check limits */
  1074. #define FLS_BKPNC       0x1000  /* back prop to PEs with NO connections */
  1075. #define FLS_FTHRESH     0x2000  /* F' threshold != 0 */
  1076. #define FLS_EOE         0x8000  /* End of epoch flag */
  1077. #define FLS_ANY_USER  (FLS_USR_SUM|FLS_USR_TRAN|FLS_USR_OUT|FLS_USR_LEARN|FLS_USR_ERROR)
  1078.  
  1079. /* global math flags */
  1080.  
  1081. #ifndef DPK
  1082. GLOBALREF  UW           um_flag;  /* user math control flag */
  1083. GLOBALREF  UL           um_micro; /* control strategy math microcode */
  1084. #endif
  1085. GLOBALREF  USR_LYR     *um_net;   /* pointer to super layer */
  1086. GLOBALREF  SL          *um_ctr;   /* counters FC2 */
  1087.  
  1088. #define UMCF_PRELYR     0x0001
  1089. #define UMCF_POSTLYR    0x0002
  1090. #define UMCF_EPOCHEND   0x0004
  1091. #define UMCF_INIT       0x0008
  1092. #define UMCF_DERIV      0x1000
  1093. #define UMCF_LEARN      0x00f0
  1094. #define UMCF_RECALL     0x0f00
  1095.  
  1096. #define IS_PRELYR       (um_flag & UMCF_PRELYR)
  1097. #define IS_POSTLYR      (um_flag & UMCF_POSTLYR)
  1098. #define IS_DERIV        (um_flag & UMCF_DERIV)
  1099. #define IS_INIT         (um_flag & UMCF_INIT)
  1100. #define IS_PRE_POST     (um_flag & (UMCF_PRELYR|UMCF_POSTLYR))
  1101. #define IS_LEARN        (um_flag & UMCF_LEARN)
  1102. #define IS_EPOCH        (um_flag & UMCF_EPOCHEND)
  1103.  
  1104. /* PE memory management functions */
  1105.  
  1106. NINT     PEVecAlc ARGLIST(( NINT ) );       /* allocate PE Vector */
  1107. USR_PE  *PEX2Ptr ARGLIST(( UW ) );          /* convert a PE # to a pointer */
  1108. UW       PEPtr2X ARGLIST(( USR_PE * ) );    /* convert a pointer to a PE # */
  1109.  
  1110. /* --- Virtual Memory Management --- */
  1111.  
  1112. USR_CN_HDR  *WAP2Real ARGLIST(( WAP ) );          /* convert a WAP to real */
  1113. WAP          WAFree ARGLIST(( WAP ) );            /* free a weight array */
  1114. WAP          WAAlloc ARGLIST(( UW, UW, UW ) );    /* alloc a weight array */
  1115. WAP          WAReAlloc ARGLIST(( UW, UW, WAP ) ); /* re-alloc a weight array */
  1116. VOID         WAPlock ARGLIST(( USR_CN_HDR * ));   /* lock routine */
  1117. VOID         WAPunlock ARGLIST(( USR_CN_HDR * )); /* unlock routine */
  1118.  
  1119. /* an array of 16 SREAL and 16 UL values which are stored with a network
  1120.    and retrived when the network is read. You may use these for any
  1121.    information which must be retained when a net is saved. It is up
  1122.    to you to avoid any conflicts in usage */
  1123.  
  1124. #define MAX_SLOTS 16
  1125.  
  1126. #ifndef DP_RUN
  1127. GLOBALREF SREAL  User_Floats[MAX_SLOTS]; /* array of floats which are
  1128.                                             stored with network */
  1129. GLOBALREF UL     User_Longs[MAX_SLOTS];  /* array of Longs which are
  1130.                                             stored with network */
  1131. GLOBALREF LAYER  **LTable;        /* The layer table */
  1132. GLOBALREF UW       LTCurN;        /* current # of used entries */
  1133. GLOBALREF USR_PE  *PE_vector;     /* processing element array */
  1134. GLOBALREF UW       PE_nvec;       /* # of vectors allocated (<=MAX_VEC) */
  1135. #else
  1136. #define User_Floats    (mptr->U_Floats)
  1137. #define User_Longs     (mptr->U_Longs)
  1138. #define LTable         (mptr->layers)
  1139. #define LTCurN         (mptr->num_lay)
  1140. #define PE_vector      (mptr->peptr)
  1141. #define PE_nvec        (mptr->alc_pes)
  1142. #endif /* ifndef DP_RUN */
  1143.  
  1144. GLOBALREF UW   PE_nnxt;         /* first "free" (maybe) PE (place to start) */
  1145.  
  1146. /* layer to index */
  1147. #define LP2LX(p) (((p)==(LAYER *)0)? (int)(-1):(p)->l_selfx)
  1148.  
  1149. /* convert a layer index to pointer */
  1150. #ifdef VMS
  1151. #define SIGNED
  1152. #else
  1153. #define SIGNED signed
  1154. #endif
  1155. #define LX2LP(x) (((LTable!=(LAYER **)0)&&(0<=(SIGNED char)(x)&&(x)<LTCurN))? LTable[(x)]:(LAYER *)0)
  1156.  
  1157. /************************************************************************/
  1158. /*                                                                      */
  1159. /*  External Definitions                                                */
  1160. /*                                                                      */
  1161. /************************************************************************/
  1162.  
  1163. /* The following defines are used by um_event() to indicate the kind
  1164.    of event which is occurring */
  1165.  
  1166. #define UME_LSTART      1 /* start learning */
  1167. #define UME_LEND        2 /* end learning */
  1168. #define UME_RSTART      3 /* start recall */
  1169. #define UME_TSTART      4 /* start test */
  1170. #define UME_REND        5 /* end recall/test */
  1171. #define UME_LOAD        6 /* network just loaded */
  1172. #define UME_SAVE        7 /* about to save network */
  1173. #define UME_DELETE      8 /* about to delete network */
  1174. #define UME_INIT        9 /* network has just been initialized */
  1175.  
  1176. /* Prototypes */
  1177.  
  1178. NINT  setup_umath ARGLIST((void));
  1179. NINT  um_event ARGLIST((XB *, XB *, USR_LYR *, NINT ));
  1180. NINT  um_chkpt ARGLIST((USR_PE *, USR_CN_HDR *, USR_LYR * ));
  1181.  
  1182. /* Auxilary Routines used in Math Functions */
  1183.  
  1184. NINT   PEWtNorm ARGLIST(( USR_PE *, NINT, NINT ) ); /* normalize wts in a PE */
  1185.  
  1186. /* --- message handling --- */
  1187.  
  1188. XB  *msg_gets ARGLIST(( NINT ) ); /* get a message from keyboard */
  1189.  
  1190. #ifdef MAC
  1191. #define PNLEN 255     /* max length for a path */
  1192. #else
  1193. #define PNLEN 63      /* max length for a path */
  1194. #endif
  1195.  
  1196. #define find_weights(wap,n,wxp) ((wap!=(USR_CN_HDR *)0)? \
  1197. (wxp= &wap->conn_table[0],(n=wap->num_conns)<=0):(wxp=(USR_CONN *)0,n=0,1))
  1198. #endif  /* ifndef _USERMATH_ */
  1199.